Writing Interactive Fiction with Twine (SHARLA SORGE's Library) by Melissa Ford

Writing Interactive Fiction with Twine (SHARLA SORGE's Library) by Melissa Ford

Author:Melissa Ford
Language: eng
Format: epub
Publisher: Que Publishing
Published: 2016-02-29T16:00:00+00:00


Adding Values to the Datamap

You assign values to the string indexes in the datamap much the same way you add values to an array. Here’s an example:

Click here to view code image

(set: $character1 to it + (datamap: "Class", "Wizard"))

Later in this chapter, I’ll teach you a second syntax you can use to add values to an index, but this first way should help you to see the fact that you have string indexes and string or numerical values assigned to those indexes.

The first word in the pair ("Class") is the data name. It is the name of the index. The second word in the pair ("Wizard") is the data value. It is the value assigned to that index. For each entry in the datamap, you have a data name and a data value. You cannot have a data name without a data value, and you cannot have a data value without a data name.

In this example, because the variable name—$character1—is so long, you may opt to use a Twine shortcut. I know, I know, I’m usually against Twine shortcuts like abbreviating the (array:) macro to (a:), but in this case, having to type a variable name that long twice every time you add a new value will take up a lot of space.

As a shortcut, you can use the keyword it to stand in for the second instance of the variable name. Because $character1 has already been set in the expression, you can refer to it with the keyword it other times within the same operation. You can’t just throw it willy-nilly into a later operation, such as (set: it to 3). But if the object being changed is already defined in the operation, you can use it to refer to it rather than write out the variable a second time.

In other words, (set: $character1 to it + (datamap: "Class", "Wizard")) is the same as (set: $character1 to $character1 + (datamap: "Class", "Wizard")).



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.